package net.dodoman.thread.ticket;

/**
 *售票机器
 * 
 * @author yanping
 * 
 */
public class TicketMachine {
	// 总票数
	private int count;

	/**
	 * 构造方法
	 * 
	 * @param count
	 *            总票数
	 */
	public TicketMachine(int count) {
		this.count = count;
	}

	/**
	 * 售票方法
	 */
	public synchronized void sale() {
		if (count == 0) {
			System.out.println("ticket has sold out");
			return;
		}
		count--;
		System.out.println("sale a ticket");
		System.out.println("remain " + count);
	}

	public boolean isSoldOut() {
		boolean isSoldOut = false;
		if (count == 0) {
			isSoldOut = true;
		}
		return isSoldOut;
	}
}